set complete=lsf
set editor='/usr/bin/emacsclient -c <file>'

highlight -a Hint text-transform: uppercase

" M-x enters command mode
map -b <A-x> :

" Emacs navigation in command line and insert mode
cmap <C-n> <Tab>
cmap <C-p> <S-Tab>
cmap <C-f> <Right>
cmap <C-b> <Left>
cmap <C-j> <CR>
map -b <C-j> <CR>
imap -b <C-j> <CR>
imap -b <C-n> <Down>
imap -b <C-p> <Up>
imap -b <C-f> <Right>
imap -b <C-b> <Left>

" Use C-f and C-b for tab browsing
map -b <C-f> <C-n>
map -b <C-b> <C-p>

" Or use them to go to the absolute left/right of the document
map -b <C-a> 0
map -b <C-e> $

" Use C-p and C-n for up/down
map -b <C-p> 2k
map -b <C-n> 2j

" Use C-v and M-v for jump scrolling
map -b <C-v> <C-d>
map -b <A-v> <C-u>

" Goto the top of the document with M-<
map -b <A-<> gg

" Goto the end of the document with M->
map -b <A->> G

" Map C-x C-s to save
map -b <C-x><C-s> <C-s>

" Use C-s and C-r for searching (n/N for next/prev as in less)
map -b <C-s> /
map -b <C-r> ?

" Copy the current URL to the clipboard with M-w
map -b <A-w> y
"
" Copy selected text to the clipboard with C-w
map -b <C-w> Y

" Paste the current clipboard selection to a new buffer with C-y
map -b <C-y> P

" Use current URL as a start for a new location with C-x C-v
map -b <C-x><C-v> O

" C-g as cancel (C-q is stop)
cmap <C-g> <Esc>
imap <C-g> <Esc>
map -b <C-g> <Esc>

" Avoid Find dialog when canceling a started command, C-x C-g
map -b <C-x><C-g> <Esc>
"
" Avoid quit on C-q, and it's more suitable for Stop here
map -b <C-q> :stop<CR>

" Kill the buffer with C-x k
map -b <C-x>k d

" Undo close tab with C-_ (also with C-Shift-t, as C-t is new tab)
map -b <C-/> u

" Exit and save the session with C-x C-c
javascript <<END_OF_SCRIPT
	userContext.confirm_and_quit = function confirm_and_quit() {
		quit = confirm("Quit Pentadactyl?");
		if (quit)
			commands.get("quitall").action();
	};
END_OF_SCRIPT

map -b <C-x><C-c> :js confirm_and_quit()<CR>

" Buffer lists with C-x b and C-x C-b
map -b <C-x>b b
map -b <C-x><C-b> B

" Open a link in a new tab with C-x t
" Open a link in the current tab with C-x l
map -b <C-x>t :t<SPACE>
map -b <C-x>l :o<SPACE>


" Switch hints to letter "j", for right hand usage
map -b j f
map -b J F
"
" Extended hint mode with M-j
"  ; - focus link, a - save, y - copy link, O - :open query, T - for :tabopen ...
map -b <A-j> ;

" We can now also use F for Shift+b/f as back/forward
map -b F L
map -b B H

" Back with Backspace as well
map <BS> H

" Use C-h i to start help
map -b <C-x>? i :help<CR>

" Close all other windows ("delete all other frames") with C-x 5 1
map -builtin <C-x>51 :winonly<CR>

" Switch to previously selected tab ("switch cursor to other window") with C-x o
map -builtin <C-x>o <C-6>

" Duplicate tab ("split window") with C-x 2
map -builtin <C-x>2 T<CR>

" Duplicate window ("split frame") with C-x 5 2
map -builtin <C-x>52 W<CR>

" Open a URL in the current buffer with C-x C-f
map -builtin <C-x><C-f> :open<SPACE>

" Open a URL based on current location in the current buffer with C-x C-v
" ("replace the contents of this buffer with new URL")
map -builtin <C-x><C-v> O

" Open a URL in a new window with C-x 5 f
map -builtin <C-x>5f :winopen<SPACE>

" Open a URL in a new background tab with C-x t
map -builtin <C-x>t t<SPACE>

" Open a URL based on current location in new background tab with C-x T
map -builtin <C-x>T T

" Open a URL in a new focussed tab with C-x C-t
"                                  with C-x 4 f
map -builtin <C-x><C-t> t!<SPACE>
map -builtin <C-x>4f t!<SPACE>

" QuickHint mode bindings
" Follow link using l to open in current buffer
" Follow link using L to open in new background tab
" Follow link using M-l to open in new focussed tab
" [Alt: Follow link using C-x l to open in new focussed tab]
" Use neighbouring ; to open extended hint mode (as per standard vimperator)
map -builtin l f
map -builtin L F
map -builtin <A-l> ;t
" map -builtin <C-x>l ;t

" Use C-h r to start pentadactyl help
" Use C-h i to go to pentadactyl index
" Use C-h t to go to pentadactyl quickstart tutorial
" Use C-h I to go to emacslik pentadactyl quickreference card
map -builtin <C-h>r :help<CR>
map -builtin <C-h>i o<SPACE>dactyl://help/index<CR>
map -builtin <C-h>t o<SPACE>dactyl://help/tutorial<CR>
map -builtin <C-h>I o<SPACE>http://www.jnanam.net/pentadactylemacs/pentadactylemacs.html<CR>

" Record a key sequence into a macro with C-x (
map -b <C-x>( q

" Play a macro with C-x e
map -b <C-x>e @

" Set a mark at the cursor with C-x r m
map -b <C-x>rm m

" Jump to the mark in the current buffer with C-x r b
map -b <C-x>rb '

" C-v was pass-next, remap to bind with default keys
map -b <C-d> <C-v>
"
" C-x C-f starts the "Open File" dialog (C-x C-s is Save)
map <C-x><C-f> <C-d><C-o>

" M-Up/Dn toggles the toolbar and scrollbars
map <A-Down> :set go+=brT<CR>
map <A-Up> :set go-=brT<CR>

" Sidebar selection with s, close with S
map -b s :sidebar<SPACE>
map -b S :sbclose<CR>

" Dialog selection with d
map d :dialog<SPACE>

" Focus the address bar with C-l
map <C-l> <C-d><C-l>

" Focus last used input field with C-c i
map <C-c>i gi

" Add a bookmark with C-c a (dialog)
map <C-c>a <C-d><C-d>

" Bookmarks search, and search by tag
map <C-c>q :bmarks<SPACE>
map <C-c>w :bmarks -tags=

" View source with C-c g, and
map <C-c>g gf
" ... in an editor with C-c e
map <C-c>e gF

" Open picture location with C-c p
map <C-c>p ;i

" Open context menu with C-c m
map <C-c>m ;c

" Open home directory with C-c f
map <C-c>f ~

" Go to home page with C-c h
map <C-c>h gh

" Go to parent directory with C-c u
map <C-c>u gu

" Go to the root of the website with C-c C-u
map <C-c><C-u> gU

" Restart with C-c C-r
map <C-c><C-r> :restart<CR>

" Tab moving helpers
map -b <A-m> :tabmove<SPACE>
map -b <A-Left> :tabmove! -1<CR>
map -b <A-Right> :tabmove! +1<CR>

" Turn off certain keybindings

map D <Nop>
map u <Nop>
map w <Nop>
map W <Nop>
map <C-u> <Nop>
map <C-d> <Nop>
map <C-u> <Nop>
map <C-x> <Nop>
map <C-h> <Nop>
map <C-x><C-f> <Nop>
map : <Nop>
map ~ <Nop>
map / <Nop>
map ? <Nop>
map $ <Nop>
map 0 <Nop>
map b <Nop>
map d <Nop>
map gg <Nop>
map gh <Nop>
map gi <Nop>
map gU <Nop>
map G <Nop>
map j <Nop>
map k <Nop>
map o <Nop>
map O <Nop>
map p <Nop>
map P <Nop>
map q <Nop>
map r <Nop>
map t <Nop>
map u <Nop>
map w <Nop>
map y <Nop>
map Y <Nop>
map ZZ <Nop>
